//
//  PopAnimation.m
//  核心动画
//
//  Created by chichaojituan521 on 2017/5/27.
//  Copyright © 2017年 linch. All rights reserved.
//

#import "PopAnimation.h"

@implementation PopAnimation


-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
    return 1;
}
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    //目的ViewController
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    
    //起始ViewController
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    
    //添加toView到上下文
    [[transitionContext containerView] insertSubview:toViewController.view belowSubview:fromViewController.view];
    
    
    [UIView transitionFromView:fromViewController.view toView:toViewController.view duration:1 options:UIViewAnimationOptionTransitionCurlDown completion:^(BOOL finished) {
        
        fromViewController.view.transform = CGAffineTransformIdentity;
        //        // 声明过渡结束时调用 completeTransition: 这个方法
        [transitionContext completeTransition:YES];//NO 的话  会闪回去
        
    }];
    
    
    
    //自定义动画
    
    //    toViewController.view.transform = CGAffineTransformMakeTranslation(414, 736);
    //
    //    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
    //
    //        fromViewController.view.transform = CGAffineTransformMakeTranslation(-414, -736);
    //
    //        toViewController.view.transform = CGAffineTransformIdentity;
    //
    //    } completion:^(BOOL finished) {
    //
    //        fromViewController.view.transform = CGAffineTransformIdentity;
    ////        // 声明过渡结束时调用 completeTransition: 这个方法
    //        [transitionContext completeTransition:YES];//NO 的话  会闪回去
    //        
    //    }];
    
}



@end
